package com.uiotsoft.util.encrypt;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class CreateSign {

	public static String creatHttpParmsString(Map<String, String> params) {

		List<String> keys = new ArrayList<String>(params.keySet());
		Collections.sort(keys);

		String prestr = "";

		for (int i = 0; i < keys.size(); i++) {
			String key = keys.get(i);
			String value = params.get(key);

			if (i == keys.size() - 1) {
				prestr = prestr + key + "=" + value;
			} else {
				prestr = prestr + key + "=" + value + "&";
			}
		}

		return prestr;
	}

	public static String getSign(Map<String, String> params) {

		String prestr = creatHttpParmsString(params);
		String reqType = params.get("reqType");
		String sign = "";
		switch (reqType) {
		case "app":
			sign = RSA.privateKeySign(prestr, SignConfig.app_private_key);
			break;
		case "snr":
			sign = RSA.privateKeySign(prestr, SignConfig.sn_private_key);
			break;
		default:
			sign = RSA.privateKeySign(prestr, SignConfig.platform_private_key);
			break;
		}

		return sign;
	}
}
